<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div id="div1" name="div1Name" class="div1Class">div1</div>
<input type="text" id="username" name="username"/>
<script type="text/javascript">
    window.onload = function () {
        var div1 = document.getElementById('div1');
        var username = document.getElementById('username');
        //获取 div 中的名称和 class
        console.log(div1.className);

        console.log(div1.getAttribute('class'));
        console.log(div1.getAttribute('name'));
        div1.setAttribute('class', 'div2Class');
        div1.setAttribute('name', 'div2Name');

        // username.setAttribute('readonly','readonly');
        // username.setAttribute('disabled','disabled');
        username.setAttribute('hidden','hidden');
    }
</script>
</body>
</html>